#ifndef T_RULES_H
#define T_RULES_H

#include "T_BasePage.h"
#include "common.h"

#define T_RulesIns T_Rules::Instance()
class ElaLineEdit;
class ElaScrollPageArea;
class ElaText;
class ElaRadioButton;

class T_Rules : public T_BasePage
{
    Q_OBJECT
public:
    T_Rules(QWidget *parent = nullptr);
    ~T_Rules();

    static T_Rules *Instance();

    enum LayoutBlock {
        LW = 0,
        LH,
        HW,
        WL,
        WH,
        HL
    };

    enum LayoutGroup {
        HX = 0,
        ZX,
        DHDL,
    };

signals:
    void addMainRect(const cutomitem &data,qreal leftMar,qreal topMar,qreal rightMar,qreal bottomMar);
    void addBlockRect(const cutomitem& data,double space,int num,int direction);
    void addSubRect(const cutomitem& data);
    void clearScene();
    void cchildItemSpaceSignal(const QStringList &list,double hSpace,double vSpace,const QString &hLayout,const QString &vLayout);

private:
    void initUI();
    void initBlockInfo();
    void initParams();
    void initModelGroup();
    void createItem();
    void createBlockItem();
    void calcModelGroupCount();
    void calcCommon(double & blockSumWidth, double &blockSumHeight, int sum);
    bool judgeSplit(double blockSumWidth,double blockSumHeight);
    bool judgeGroup();
    void calcResult();

private:
    ElaLineEdit *m_totalWLe{nullptr};
    ElaLineEdit *m_totalHLe{nullptr};
    ElaLineEdit *m_totalHDLe{nullptr};
    ElaLineEdit *m_cLe{nullptr};
    ElaLineEdit *m_bLe{nullptr};
    ElaLineEdit *m_blockValueLe{nullptr};
    ElaLineEdit *m_blockAhValueLe{nullptr};
    ElaLineEdit *m_blockNumLe{nullptr};
    ElaLineEdit *m_blockSingleNumLe{nullptr};
    ElaLineEdit *m_groupNumLe{nullptr};
    ElaScrollPageArea *m_blockInfoArea{nullptr};
    ElaScrollPageArea *m_paramsArea{nullptr};
    ElaScrollPageArea *m_modelGroupArea{nullptr};
    ElaRadioButton *m_hButton{nullptr};
    ElaRadioButton *m_vButton{nullptr};
    ElaRadioButton *m_ddButton{nullptr};
    ElaRadioButton *m_lwButton{nullptr};
    ElaRadioButton *m_lhButton{nullptr};
    ElaRadioButton *m_hwButton{nullptr};
    ElaRadioButton *m_wlButton{nullptr};
    ElaRadioButton *m_whButton{nullptr};
    ElaRadioButton *m_hlButton{nullptr};
    int m_direction{0};
    LayoutBlock m_layout{LW};
    LayoutGroup m_layout_group{HX};
    BlockInfo m_blockInfo{};
    bool m_main_is_swap{false};
    double m_duan_value_H;
    double m_duan_value_V;
    int m_pack_count_max{0};
    int m_splitInt{1};
    double m_single_w;
    double m_single_h;
    QStringList m_list_groups;
    int m_row_max;  //group最多行
    int m_col_max;  //group最多列
    double m_sum_block_dh;
    bool m_is_allow_create{false};  //允许生成
    bool m_is_import_excel{false};  //是否导入电信参数表
};

#endif // T_RULES_H
